package net.georel.representation.categorisation.decisionanalysis;

import net.georel.representation.categorisation.decisionanalysis.ElementaryInformationProcesses.EIP;

public class Decision_Rules {

	private ElementaryInformationProcesses elementaryInformationProcesses = new ElementaryInformationProcesses();
	
	public Object getSingleWeightedAdditiveDecisionRuleWeights(int numOfAlternatives, boolean returnWeights){		
		elementaryInformationProcesses.clearEIPs();
		for (int i = 0;i<numOfAlternatives;i++){		
			elementaryInformationProcesses.addEIP(EIP.READ);
			
				for (int j = i;j<numOfAlternatives;j++){				
					elementaryInformationProcesses.addEIP(EIP.MOVE);
					elementaryInformationProcesses.addEIP(EIP.READ);
					elementaryInformationProcesses.addEIP(EIP.COMPARE);
				}					
			}
		
		if(returnWeights==true){		
		return(elementaryInformationProcesses.getTotalWeightedEIPs());	
		}
		
		else{
		return(elementaryInformationProcesses.getTotalEIPs());	
		}
		
		}
	
	
public Object getMultiWeightedAdditiveDecisionRuleWeights(int numOfAlternatives, int numOfAttributes,boolean returnWeights){		
	elementaryInformationProcesses.clearEIPs();
		for (int i = 0;i<numOfAlternatives;i++){
			for (int v = 0;v<numOfAttributes;v++){
				//getValue
				elementaryInformationProcesses.addEIP(EIP.READ);
				//getWeight
				elementaryInformationProcesses.addEIP(EIP.READ);
				//Weight*Value
				elementaryInformationProcesses.addEIP(EIP.PRODUCT);
				//Add to Total
				elementaryInformationProcesses.addEIP(EIP.ADD);
				}

			
				for (int j = i;j<numOfAlternatives;j++){	
					for (int x = 0;x<numOfAttributes;x++){
						//getValue
						elementaryInformationProcesses.addEIP(EIP.READ);
						//getWeight
						elementaryInformationProcesses.addEIP(EIP.READ);
						//Weight*Value
						elementaryInformationProcesses.addEIP(EIP.PRODUCT);
						//Add to Total
						elementaryInformationProcesses.addEIP(EIP.ADD);
					}
				}
				elementaryInformationProcesses.addEIP(EIP.COMPARE);
			}
		
		if(returnWeights==true){		
		return(elementaryInformationProcesses.getTotalWeightedEIPs());	
		}
		
		else{
		return(elementaryInformationProcesses.getTotalEIPs());	
		}
		
		}
	

public Object getSingleEBADecisionRuleWeights(int numOfAlternatives, boolean returnWeights){

		elementaryInformationProcesses.clearEIPs();
		
		while(numOfAlternatives>2){
		for (int i = 0;i<numOfAlternatives;i++){
		elementaryInformationProcesses.addEIP(EIP.READ);
		elementaryInformationProcesses.addEIP(EIP.COMPARE);
			if(i>numOfAlternatives/2){
				elementaryInformationProcesses.addEIP(EIP.ELIMINATE);
			}
		}
		numOfAlternatives=numOfAlternatives/2;
		}
				
			if(returnWeights==true){		
			return(elementaryInformationProcesses.getTotalWeightedEIPs());	
			}
			
			else{
			return(elementaryInformationProcesses.getTotalEIPs());	
			}
		
	}

public Object getMultiEBADecisionRuleWeights(int numOfAlternatives, int numOfAttributes,boolean returnWeights){

	elementaryInformationProcesses.clearEIPs();
	
	for(int i = 0;i<numOfAttributes;i++){
		//getWeight
		elementaryInformationProcesses.addEIP(EIP.READ);
		//compare it to highest weight so far
		elementaryInformationProcesses.addEIP(EIP.COMPARE);
	}
	
	while(numOfAlternatives>2){
		for (int i = 0;i<numOfAlternatives;i++){
		elementaryInformationProcesses.addEIP(EIP.READ);
		elementaryInformationProcesses.addEIP(EIP.COMPARE);
			if(i>numOfAlternatives/2){
				elementaryInformationProcesses.addEIP(EIP.ELIMINATE);
			}
		}
		numOfAlternatives=numOfAlternatives/2;
		}
				
			if(returnWeights==true){		
			return(elementaryInformationProcesses.getTotalWeightedEIPs());	
			}
			
			else{
			return(elementaryInformationProcesses.getTotalEIPs());	
			}
	
}


	
}
	
	
	
